package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EnvironmentalArticles;
import com.ruoyi.system.service.IEnvironmentalArticlesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * articlesController
 * 
 * @author zrj
 * @date 2025-07-11
 */
@RestController
@RequestMapping("/system/articles")
public class EnvironmentalArticlesController extends BaseController
{
    @Autowired
    private IEnvironmentalArticlesService environmentalArticlesService;

    /**
     * 查询articles列表
     */
    @PreAuthorize("@ss.hasPermi('system:articles:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnvironmentalArticles environmentalArticles)
    {
        startPage();
        List<EnvironmentalArticles> list = environmentalArticlesService.selectEnvironmentalArticlesList(environmentalArticles);
        return getDataTable(list);
    }

    /**
     * 导出articles列表
     */
    @PreAuthorize("@ss.hasPermi('system:articles:export')")
    @Log(title = "articles", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EnvironmentalArticles environmentalArticles)
    {
        List<EnvironmentalArticles> list = environmentalArticlesService.selectEnvironmentalArticlesList(environmentalArticles);
        ExcelUtil<EnvironmentalArticles> util = new ExcelUtil<EnvironmentalArticles>(EnvironmentalArticles.class);
        util.exportExcel(response, list, "articles数据");
    }

    /**
     * 获取articles详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:articles:query')")
    @GetMapping(value = "/{articleId}")
    public AjaxResult getInfo(@PathVariable("articleId") Long articleId)
    {
        return success(environmentalArticlesService.selectEnvironmentalArticlesByArticleId(articleId));
    }

    /**
     * 新增articles
     */
    @PreAuthorize("@ss.hasPermi('system:articles:add')")
    @Log(title = "articles", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnvironmentalArticles environmentalArticles)
    {
        return toAjax(environmentalArticlesService.insertEnvironmentalArticles(environmentalArticles));
    }

    /**
     * 修改articles
     */
    @PreAuthorize("@ss.hasPermi('system:articles:edit')")
    @Log(title = "articles", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnvironmentalArticles environmentalArticles)
    {
        return toAjax(environmentalArticlesService.updateEnvironmentalArticles(environmentalArticles));
    }

    /**
     * 删除articles
     */
    @PreAuthorize("@ss.hasPermi('system:articles:remove')")
    @Log(title = "articles", businessType = BusinessType.DELETE)
	@DeleteMapping("/{articleIds}")
    public AjaxResult remove(@PathVariable Long[] articleIds)
    {
        return toAjax(environmentalArticlesService.deleteEnvironmentalArticlesByArticleIds(articleIds));
    }
}
